package 力扣日常刷题.木22一月.第06天0114;

/**
 * @author 帅小伙
 * @date 2022/1/14
 * @description
 */
public class Demo01中等多路归并jz丑数 {


    public int nthUglyNumber(int n) {
        int a = 0, b = 0, c = 0;
        int[] arr = new int[n + 1];
        arr[0] = 1;

        for (int i = 1; i < n; i++) {
            int ax = arr[a] * 2, bx = arr[b] * 3, cx = arr[c] * 4;
            arr[i] = Math.min(Math.min(ax, bx), cx);
            if (arr[i] == ax) a++;
            if (arr[i] == bx) b++;
            if (arr[i] == cx) c++;
        }
        return arr[n-1];
    }
}
